
**********************************************************************************************************;
**********************************************************************************************************;
* Gets EINs from W2 renames fas_ein; 
* Do this in Stata;


global projectdir "~"
global datadir "$projectdir/data"

clear
cd $datadir/intermediate_files

clear
gen year=.
tempfile stackyears
save `stackyears', replace


forvalues i = 2005/2016 {

	display in red "--------- Year `i' ----------"

	cd $datadir/raw_pulls/w2_usiris
	use iw2ty`i'_summaryrecs_usiris_2018q4, clear
	append using iw2ty`i'_dups_flagged_usiris_2018q4
	keep if dup_flag == "N1" | dup_flag == "AX" | dup_flag == "X1" | dup_flag == "D1" | dup_flag == "FX" | dup_flag == "TX"
	keep pik ein wage_tip year
	
	append using `stackyears'
	
	tempfile stackyears
	save `stackyears', replace
}

keep ein
duplicates drop
gen fas_ein = "EINUS" + ein

insobs 1, before(1)

replace ein = "EIN" if missing(ein)

export delimited using "$datadir/raw_pulls/w2_usiris/w2_eins.csv", replace

